home *** CD-ROM | disk | FTP | other *** search
- /*
- SNEWS 2.0
-
- addgroup - add a new newsgroup
-
-
- Copyright (C) 1991 John McCombs, Christchurch, NEW ZEALAND
- john@ahuriri.gen.nz
- PO Box 2708, Christchurch, NEW ZEALAND
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License, version 1, as
- published by the Free Software Foundation.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- See the file COPYING, which contains a copy of the GNU General
- Public License.
-
- Atari version ported by Graham Judd - gjudd@siward.demon.co.uk
- */
-
- /*---------------------------- Source Control ------------------------------*/
-
- /*
- * $Id: ADDGROUP.C,v 1.2 1994/02/05 18:46:56 gbj Exp user $
- */
-
- /****************************************************************************
- * 19 Jul 92 1.2 GT Extra parameter in find_news_group (). *
- * 5 Sep 92 1.3 MSM Snews 1.90 *
- * Information message *
- * Add to ng file *
- * 21 Nov 92 1.4 MSM Wrong line ending corrected *
- * 20 Mar 93 1.5 MSM Wrong line ending in ng file also corrected *
- * 3 Jun 93 1.6 MSM Snews 2.0 *
- * make ng an optional file *
- ****************************************************************************/
-
- #include <io.h>
- #include <fcntl.h>
-
- #include "defs.h"
- #include "locking.h"
-
- #ifdef ATARI
- void delay(size_t millisecs);
- #include "fileops.h"
- #endif
-
- INFO my_stuff;
-
-
- /*---------------------------- main ---------------------------------------*/
- void main(int argc, char *argv[])
- {
-
- /*
- * Add newsgroups. All that has to be done is stick the new group
- * in the active file, after checking that it doesn't already exist.
- * It aint pretty, but it works.
- */
-
- int i;
- char buf[256], buf2[256], *p, txt_name[20];
- int added, added2;
- time_t t;
- ACTIVE *gp;
- FILE *tmp;
- FILE *active_file, *new_active_file;
- int junk_flag; /* nz - posting to junk */
-
- #ifndef __TURBOC__
- #ifndef ATARI
- clock_t goal;
- #endif
- #endif
-
- if (argc > 1) {
-
- if (!load_stuff()) {
- fprintf(stderr, "Couldn't read rc info\n");
- }
-
- /*
- * Check for active file. If there is none:
- * - create it with a single entry 'junk'.
- * - ensure that the newsbase directory exists
- * - create an empty junk text file and index file
- */
-
- printf("Demon Internet Simple news Version %d.%02d [build %d]\n", rmj, rmm, rup);
- printf("Add New Newsgroup.\n");
- sprintf(buf, "%sactive", my_stuff.news_dir);
- if (access(buf, 0) != 0) {
- active_file = fopen(buf, "wb");
- fprintf(active_file, "junk 00000000 00000000 00000000 y\n");
- fclose(active_file);
- }
-
- /* ensure that the news base file exists - just try to create it */
-
- sprintf(buf, "%snewsbase", my_stuff.news_dir);
- mkdir(buf);
- sprintf(buf, "%snewsbase\\00000000", my_stuff.news_dir);
- if (access(buf, 0) != 0) {
- if ((tmp = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "addgroup: cannot create file %s\n", buf);
- exit(1);
- }
- fclose(tmp);
- }
- sprintf(buf, "%snewsbase\\00000000.idx", my_stuff.news_dir);
- if (access(buf, 0) != 0) {
- if ((tmp = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "addgroup: cannot create file %s\n", buf);
- exit(1);
- }
- fclose(tmp);
- }
-
- load_active_file();
- close_active();
-
- for (i = 1; i < argc; i++) {
-
- /* check that the group doesn't already exist */
- gp = find_news_group(argv[i], &junk_flag);
-
- if ((stricmp(argv[i], "junk") != 0) &&
- (stricmp(gp->group, "junk") == 0)) {
-
- /* open the active file */
- sprintf(buf, "%sactive", my_stuff.news_dir);
- if ((active_file = fopen(buf, "rb")) == NULL) {
- fprintf(stderr, "addgroup: cannot open active file\n");
- exit(1);
- }
- /* create new one */
- sprintf(buf, "%sactive.new", my_stuff.news_dir);
- if ((new_active_file = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "addgroup: cannot create %s\n", buf);
- exit(1);
- }
- added = added2 = FALSE;
- if (active_file != NULL) {
-
- /* delay ensures names are different - ahem */
- #ifdef __TURBOC__
- delay(1000);
- #else
- #ifdef ATARI
- delay(1000);
- #else
- goal = 2000 + clock();
- while (goal > clock());
- #endif
- #endif
- sprintf(txt_name, "%ld", time(&t));
- if (strlen(txt_name) > 8) {
- strcpy(txt_name, txt_name + (strlen(txt_name) - 8));
- }
-
- /*
- * Check newbase name is not already used.
- * If not create an empty newsbase and index files.
- */
-
- sprintf(buf, "%snewsbase\\%s", my_stuff.news_dir, txt_name);
- if (access(buf, 0) != 0) {
-
- if ((tmp = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "addgroup: cannot create file %s\n", buf);
- exit(1);
- }
- fclose(tmp);
- sprintf(buf, "%snewsbase\\%s.idx", my_stuff.news_dir, txt_name);
- if ((tmp = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "addgroup: cannot create file %s\n", buf);
- exit(1);
- }
- fclose(tmp);
-
- }
- else {
- fprintf(stderr, "addgroup: newsbase name collision - try again\n");
- fclose(new_active_file);
- unlink(buf);
- exit(1);
- }
-
- while (fgets(buf, 255, active_file) != NULL) {
-
- strcpy(buf2, buf);
- p = strtok(buf2, " \t");
-
- /* the active file entry */
- if ((stricmp(argv[i], p) < 0) && !added) {
- fprintf(new_active_file, "%s %s 00000000 00000000 y\r\n",
- argv[i], txt_name);
- added = TRUE;
- fprintf(stderr, "addgroup: News group %s successfully added\n", argv[i]);
-
- }
- if (fputs(buf, new_active_file) == EOF) {
- fprintf(stderr, "addgroup: couldn't write new active file\n");
- }
- }
- }
- if (!added) {
- fprintf(new_active_file, "%s %s 00000000 00000000 y\r\n",
- argv[i], txt_name);
- fprintf(stderr, "addgroup: News group %s successfully added\n", argv[i]);
- }
- fclose(active_file);
- fclose(new_active_file);
-
- sprintf(buf, "%sactive.bak", my_stuff.news_dir);
- unlink(buf);
- sprintf(buf2, "%sactive", my_stuff.news_dir);
- rename(buf2, buf);
- sprintf(buf, "%sactive.new", my_stuff.news_dir);
- rename(buf, buf2);
-
- sprintf(buf, "%sng", my_stuff.news_dir);
- if ((active_file = fopen(buf, "rb")) == NULL) {
- /* fprintf(stderr, "addgroup: permission file ng does not exist\n"); */
- }
- else {
- sprintf(buf, "%sng.new", my_stuff.news_dir);
- if ((new_active_file = fopen(buf, "wb")) == NULL) {
- fprintf(stderr, "addgroup: cannot create %s\n", buf);
- exit(1);
- }
- while (fgets(buf, 255, active_file) != NULL) {
-
- strcpy(buf2, buf);
- p = strtok(buf2, " \t");
-
- /* the active file entry */
- if ((stricmp(argv[i], p) < 0) && !added2) {
- fprintf(new_active_file, "%s\r\n", argv[i]);
- added2 = TRUE;
- fprintf(stderr, "addgroup: Posting permitted to %s\n", argv[i]);
- }
- if (fputs(buf, new_active_file) == EOF) {
- fprintf(stderr, "addgroup: couldn't write new ng file\n");
- }
- }
-
- if (!added2) {
- fprintf(new_active_file, "%s\r\n", argv[i]);
- fprintf(stderr, "addgroup: Posting permitted to %s\n", argv[i]);
- }
- (void) fclose(active_file);
- (void) fclose(new_active_file);
-
- sprintf(buf, "%sng.bak", my_stuff.news_dir);
- unlink(buf);
- sprintf(buf2, "%sng", my_stuff.news_dir);
- rename(buf2, buf);
- sprintf(buf, "%sng.new", my_stuff.news_dir);
- rename(buf, buf2);
- }
-
- }
- else {
- fprintf(stderr, "addgroup: newsgroup %s already exists\n", argv[1]);
- }
-
- }
-
- close_active_file();
-
- }
- else {
- printf("USAGE: addgroup newsgroup names....\n");
- }
-
- }
-
-